/**
 * 
 */
package net.entelijan.cobean.bind.impl;

import net.entelijan.cobean.bind.IColumn;
import net.entelijan.cobean.bind.IColumnBinding;

import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;

class SpringColumn implements IColumn {

    private IColumnBinding<?> binding;

    public SpringColumn(IColumnBinding<?> binding) {
        this.binding = binding;
    }

    public String getName() {
        String re = this.binding.getModelProperty();
        if (this.binding.getName() != null) {
            re = this.binding.getName();
        }
        return re;
    }

    public Object getValue(Object row) {
        BeanWrapper wrappedRow = new BeanWrapperImpl(row);
        return wrappedRow.getPropertyValue(this.binding.getModelProperty());
    }
}